<?php
namespace app\admin\controller;

use app\admin\module\ArticleModule;
use app\BaseController;
use app\Request;
use app\common\validate\Article as ArticleValidate;
use think\Exception;

class Article extends BaseController {

    public function index(Request $request){
        $pageSize = $request->param('pageSize',10);
        $data = ArticleModule::page($pageSize);
        return $this->success('ok',$data);
    }

    public function create(Request $request){
        $post = $request->post();
        $validate = new ArticleValidate();
        if(!$validate->check($post)){
            throw new Exception($validate->getError());
        }
        ArticleModule::create($post);
        return $this->success('ok');
    }

    public function update(Request $request){
        $post = $request->post();
        $validate = new ArticleValidate();
        if(!$validate->check($post)){
            throw new Exception($validate->getError());
        }
        ArticleModule::update($post);
        return $this->success('ok');
    }

    public function remove(Request $request){
        $id = $request->param('id');
        ArticleModule::del($id);
        return $this->success('ok');
    }

}